package com.itheima.poi;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class PoiTest {
    public static void main(String[] args) throws Exception {
//        XSSFWorkbook sheets = new XSSFWorkbook("E:\\桌面\\mytest.xlsx");
        XSSFWorkbook sheets = new XSSFWorkbook();
        XSSFSheet sheet = sheets.createSheet("黑马");
//        第一行数据
        XSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("姓名");
        row.createCell(1).setCellValue("年龄");
        row.createCell(2).setCellValue("密码");
//        第二行数据
        XSSFRow row_1 = sheet.createRow(1);
        row_1.createCell(0).setCellValue("itcast");
        row_1.createCell(1).setCellValue("22");
        row_1.createCell(2).setCellValue("12346");
//        保存
        FileOutputStream fos = new FileOutputStream("E:\\桌面\\mytest.xlsx");
        sheets.write(fos);
        fos.flush();
        fos.close();
        sheets.close();
    }
}
